#include <QtGui/QApplication>
#include "contextviewer.h"
#include "stdinreader.h"

#include <QDebug>

int main(int argc, char *argv[])
{
    //QApplication::setGraphicsSystem("raster");
    QApplication a(argc, argv);
    QStringList lArg = a.arguments();
    ContextViewer w;
    StdInReader reader;

    QString appName;
    QString qmlFile;
    bool show = false;
    foreach (QString s,lArg){
       // qDebug()<<"arg:"<<s;
        if(s.endsWith(".qml")){
            qmlFile=s;
        }else if("--show" == s){
            show=true;
        }else if("--hideWhenLostFocus" == s){
           w.setHideWhenUnfocus(true);
        }else if (s.contains("=")) {
            QStringList valName = s.split("=");

            QString argName = valName.at(0);
            argName.remove(0,1);
            if(argName == "name"){
                appName=valName.at(1);
            }else if("size"==argName){
                w.fixeSize(valName.at(1));
            }else if("pos"==argName){
                w.fixePosition(valName.at(1));
            }else if("flags"==argName){
                w.setWinFlags(valName.at(1));
            }
            //argName = "Qarg." + argName;
            qDebug()<<"<"<<argName<<"> is ["<<valName.at(1)<<"]";
            //w.rootContext()->setContextProperty(argName, valName.at(1));

        }
    }

    qDebug()<<"qmlFile:"<<qmlFile;
    qDebug()<<"appName:"<<appName;
    w.setWindowTitle(appName);
    w.setReader(&reader);
    if(!qmlFile.isEmpty()){
        w.loadFile(qmlFile);
    }
    reader.start();
    if(show){
        w.onShow();
    }

    return a.exec();
}
